package com.tianyi.sfzy1.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tianyi.sfzy1.domain.Consultant;
import com.tianyi.sfzy1.domain.Consultationappointment;
import com.tianyi.sfzy1.mapper.ConsultantMapper;
import com.tianyi.sfzy1.mapper.ConsultationappointmentMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ConsultantService {
    @Autowired
    private ConsultantMapper consultantMapper;

    public PageInfo<Consultant> findAllConsultant(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Consultant> consultantList = consultantMapper.findAllConsultant();
        PageInfo<Consultant> pageInfo = new PageInfo<>(consultantList);
        return pageInfo;
        //return consultantMapper.findAllConsultant();
    }
    public int deleteByPrimaryKey(List<Integer> ids) {
        return consultantMapper.deleteByPrimaryKey(ids);
    }
//    添加一名咨询师
    public int insert(Consultant record) {
        return consultantMapper.insert(record);
    }
//   更新一名咨询师
    public int updateByPrimaryKeySelective(Consultant record) {
        return consultantMapper.updateByPrimaryKeySelective(record);
    }
//    模糊搜索
    public List<Consultant> findConsultantByCondition(@Param("realname") String realname,
                                                      @Param("phone") String phone,
                                                      @Param("gender") String gender,
                                                      @Param("levelId") Integer levelId) {
        return consultantMapper.findConsultantByCondition( realname, phone, gender, levelId);
    }
    public int deleteConsultant(int id){
        return consultantMapper.deleteConsultant(id);
    }


    public Consultant findConsultantById(Integer id) {
        return consultantMapper.findConsultantById(id);
    }

//  登录
    public int login(String username, String password){
        Consultant consultant = consultantMapper.login(username,password);
        if (consultant != null && consultant.getPassword().equals(password)){
            return 1;
        }
        return 0;
    }

//    根据用户名查询咨询师id
    public Consultant findByUsername(String username){
        return consultantMapper.findByUsername(username);
    }



    //查询所有的咨询师
    public List<Consultant> findConsultant2() {
        return consultantMapper.findAllConsultant2();
    }

    //根据id查询咨询师
    //孟迪
    public Consultant findById(Long id){
        return consultantMapper.selectByPrimaryKey(id);
    }

    //根据id修改密码
    public int updatePassword(int consultantId, String password){
        return consultantMapper.updatePassword(consultantId,password);
    }

    //根据咨询师等级level_id和擅长领域specialization_id查询所有咨询师
    public List<Consultant> findConsultantByLevelAndSpecialization(Integer level_id, Integer specialization_id) {
        return consultantMapper.findConsultantByLevelAndSpecialization(level_id, specialization_id);
    }

    //根据地区、咨询师等级、性别、咨询方式、擅长领域查询咨询师
    public List<Consultant> findConsultantByFilters(@Param("area") String area,
                                                    @Param("levelId") Integer levelId,
                                                    @Param("gender") String gender,
                                                    @Param("chargeTypeId") Integer chargeTypeId,
                                                    @Param("tags") ArrayList<String> tags){
        return consultantMapper.findConsultantByFilters(area, levelId, gender, chargeTypeId, tags);
    }

    public List<Consultant> findConsultantcertificateById(Integer id) {
        return consultantMapper.findConsultantcertificateById(id);
    }

//    根据id查询咨询师
    public Consultant findById(int consultantId){
        return consultantMapper.findById(consultantId);
    }

//    根据咨询师id修改咨询师信息
    public int updateConsultant(int consultantId,String realname,String phone,int age,String gender){
        return consultantMapper.updateConsultant(consultantId,realname,phone,age,gender);
    }

    //根据咨询师id修改咨询师头像
    public int updateConsultantAvatar(int consultantId,String avatar){
        return consultantMapper.updateConsultantAvatar(consultantId,avatar);
    }
}
